import { getCookie, setCookie, removeCookie } from '@utils/jsCookie.js'
import { USERINFO } from '@/constant'
import { defineStore } from 'pinia'
export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: getCookie(USERINFO) || null
  }),

  actions: {
    async login(userInfo) {
      setCookie(USERINFO, userInfo)
      this.userInfo = userInfo
    },
    async logout() {
      removeCookie(USERINFO)
      this.userInfo = null
    }
  }
})
